#encoding=utf-8

import datetime

from django.db import models
from django.contrib.auth.models import User, Group
from django.db.models.signals import post_save
from django.forms import ModelForm, PasswordInput
from django.contrib.admin.widgets import *

from andy_manager import settings


UPLOAD_ROOT = settings.UPLOAD_ROOT

#model 中有的列，保证数据库要有，否则会报错。反之可以允许数据库的列比model的多

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    nickname = models.CharField("昵称", max_length=50, null=True)
    head_img = models.ImageField("头像", upload_to=UPLOAD_ROOT+"/headimg", max_length=200, blank=True)
    sex = models.CharField("性别", max_length=2, null=True, blank=True)
    telephone = models.CharField("电话", max_length=15, null=True, blank=True)
    qq = models.CharField("QQ", max_length=20, null=True, blank=True)
    create_date = models.DateTimeField("创建时间", default=datetime.datetime.now)

    def __str__(self):
        return "%s (%s)" % (self.user_id, self.nickname)

    class Meta:
        verbose_name = '用户信息'
        verbose_name_plural = '用户信息记录'

def create_user_profile(sender, instance, created, **kwargs):
    if created:
        print created,kwargs,instance
        profile, created = UserProfile.objects.get_or_create(user=instance)
        #print profile, created

post_save.connect(create_user_profile, sender=User)

class HXHUserInfo(models.Model):
    uid = models.CharField("用户ID", max_length=32)
    username = models.CharField("用户名称", max_length=32)
    account = models.CharField("用户帐号", max_length=32)
    pf = models.CharField("所属平台", max_length=12)
    #pf=models.ForeignKey(PlatformInfo,to_field='pf_id',verbose_name='所属平台')
    pf1 = models.CharField("所属次平台", max_length=12, null=True)
    server_id = models.CharField("服务器ID", max_length=12)
    body = models.TextField()
    create_date = models.DateTimeField("注册时间")
    game_time = models.DateTimeField("游戏时间", null=True)

    def __str__(self):
        return self.uid

    class Meta:
        verbose_name = '猎人用户信息'
        verbose_name_plural = '猎人用户信息'


class HXHPayInfo(models.Model):
    order_id = models.CharField("订单号", max_length=32)
    uid = models.CharField("用户ID", max_length=32)
    money = models.FloatField("金额")
    body = models.TextField()
    create_date = models.DateTimeField()

    def __str__(self):
        return self.order_id

    class Meta:
        verbose_name = '猎人充值信息'
        verbose_name_plural = '猎人充值信息'

#猎人消费
class HXHConsumerInfo(models.Model):
    uid = models.CharField("用户ID", max_length=32)
    amt = models.FloatField("金额")
    unit = models.CharField("币种", max_length=32)
    create_date = models.DateTimeField('消费时间')

    def __str__(self):
        return self.uid

    class Meta:
        verbose_name = '猎人消费信息'
        verbose_name_plural = '猎人消费列表'

#用户登录日志
class HXHUserLogin(models.Model):
    uid = models.CharField("用户ID", max_length=32)
    pf = models.CharField("所属平台", max_length=12)
    server_id = models.CharField("服务器ID", max_length=12)
    ip = models.CharField("IP", max_length=15)
    login_time = models.DateTimeField("登陆时间")
    create_date = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.uid

    class Meta:
        verbose_name = '用户登录日志'
        verbose_name_plural = '用户登录日志列表'



#平台表
class PlatformInfo(models.Model):
    name = models.CharField("名称", max_length=32)
    pf_id = models.CharField("编号", max_length=32,unique=True)
    games = models.CharField("游戏ID", max_length=32)
    gameurl=models.CharField("游戏网址", max_length=200)
    create_date = models.DateTimeField("创建时间",auto_now_add=True)

    def __str__(self):
        return self.pf_id

    class Meta:
        verbose_name = '平台信息'
        verbose_name_plural = '平台信息列表'

#游戏表
class GameInfo(models.Model):
    gameid = models.CharField("游戏编码", max_length=32,unique=True)
    gamename = models.CharField("游戏名称", max_length=32)
    explain = models.TextField("游戏说明")
    STATUS_CHOICES = (
         (0, u'关闭'),
        (1, u'开放'),
    )
    status = models.IntegerField("状态",default=0,choices=STATUS_CHOICES)
    FEE_CHOICES = (
         (0, u'房主'),
        (1, u'参与者'),
    )
    feetype = models.IntegerField("扣费模式",default=0,choices=FEE_CHOICES)
    roundkey = models.IntegerField("局数key",default=0)
    FREE_CHOICES = (
         (0, u'否'),
        (1, u'是'),
    )
    isfree=models.IntegerField("免费",default=0,choices=FREE_CHOICES)

    def __str__(self):#关联时显示的信息
        return self.gamename

    class Meta:
        verbose_name = '游戏管理'
        verbose_name_plural = '游戏列表'

# 房间配置表
class RoomInfo(models.Model):
    room_type = models.IntegerField("房间类型", default=1)
    name = models.CharField("名称", max_length=32, default='test')
    min_join_gold = models.IntegerField("入场金币", default=0)
    min_master_gold = models.IntegerField("上庄金币", default=0)
    grab_master_bets = models.CharField("抢庄加注", max_length=32, default='10,50,100')  # 多个逗号隔开
    player_bets = models.CharField("闲家下注", max_length=32, default='10,50,100')  # 多个逗号隔开
    master_percent = models.IntegerField("上庄佣金", default=5)
    table_fee = models.IntegerField("桌租", default=5)
    normal_profit_percent = models.IntegerField("普通盈利佣金", default=5)
    sweep_profit_percent = models.IntegerField("通杀赢利佣金", default=6)
    table_max_player = models.IntegerField("单桌人数上限", default=100)
    grab_master_time = models.IntegerField("抢庄时间", default=15)
    master_choose_seat_time = models.IntegerField("定庄时间", default=10)
    player_bet_time = models.IntegerField("下注时间", default=30)
    player_max_bet_times = models.IntegerField("下注区上限", default=5)
    tables = models.CharField("桌子列表", max_length=32, default='1,2,3')  # 会拼上房间类型前缘,多个逗号隔开
    create_time = models.DateTimeField('抓取时间', auto_now_add=True)
    is_active = models.IntegerField('是否有效', default=1)
    #exchange_rate=models.IntegerField('兑换比率')

    def __str__(self):
        return self.name

    class Meta:
        verbose_name = '房间列表'
        verbose_name_plural = '房间列表'


# #房间列表
# class RoomInfo(models.Model):
#     roomid = models.IntegerField("房间ID")
#     #parid = models.ForeignKey(GameInfo,to_field='gameid',verbose_name="游戏ID"),unique=True
#     parid = models.ForeignKey(GameInfo,verbose_name="游戏ID")
#     roomname = models.CharField("房间名称", max_length=32)
#     TYPE_CHOICES = (
#          (0, u'金币'),
#          (1, u'道具'),
#     )
#     consumertype = models.IntegerField("消耗类型",default=0,choices=TYPE_CHOICES)
#     consumerpoint = models.IntegerField("消耗量",default=0,)
#     #openprice=models.FloatField("成局价格",default=0,)
#
#     def __str__(self):
#         return self.roomname#是字符才行
#
#     class Meta:
#         verbose_name = '房间管理'
#         verbose_name_plural = '房间列表'


#代理表
class AgentInfo(models.Model):
    account = models.CharField("代理帐号", max_length=32,unique=True,default='')
    classid = models.CharField("级别编号", max_length=32, null=True,default='')
    parentid = models.ForeignKey("self",verbose_name="上级代理帐号", null=True,default=None, blank=True)
    username = models.CharField("代理名称", max_length=32,default='')
    password = models.CharField("代理密码", max_length=128,default='')
    discount = models.FloatField("折扣",default=0)
    #rebate = models.FloatField("返利",default=0)
    gamepoint = models.IntegerField("金币",default=0)
    status = models.IntegerField("状态",default=1)#1正常，0拉黑
    CHECK_CHOICES = (
         (0, u'否'),
         (1, u'是'),
    )
    ischeck = models.IntegerField("审核",default=0,choices=CHECK_CHOICES)#1是，0否
    create_time = models.DateTimeField('注册时间',auto_now_add=True)
    create_ip=models.IPAddressField("注册IP",null=True,default=None, blank=True)
    login_time = models.DateTimeField('登陆时间',null=True,default=None, blank=True)
    login_ip=models.IPAddressField("登陆IP",null=True,default=None, blank=True)
    comrate= models.FloatField("占成比",default=0)
    allmoney=models.FloatField("总提成",default=0)
    lastmoney=models.FloatField("剩余提成",default=0)
    platform= models.ForeignKey(PlatformInfo,verbose_name='所属平台',blank=True,null=True)
    bindcode = models.IntegerField("绑定码",default=0)#sd_jn

    def __str__(self):
        return '%s(%s)'%(self.account,self.username)

    class Meta:
        verbose_name = '代理信息'
        verbose_name_plural = '代理列表'
        permissions = (
            #("view_discussion", "Can view 代理结算"),
            #("reply_discussion", "Can reply discussion"),
            #("close_discussion", "Can remove a discussion by setting its status as closed"),
        )

#代理银行表
class AgentBank(models.Model):
    truename = models.CharField("真名", max_length=32,unique=True)
    phone = models.CharField("手机号", max_length=32, null=True)
    agentid = models.ForeignKey(AgentInfo,verbose_name="代理帐号")
    bankcard = models.CharField("卡号", max_length=32)
    Bank_CHOICES = (
         (0, u'中国银行'),
         (1, u'工商银行'),
        (2, u'农业银行'),
        (3, u'建设银行'),
        (4, u'招商银行'),
        (10, u'其它银行'),
    )
    banktype = models.IntegerField("银行",default=10,choices=Bank_CHOICES)#1是，0否
    branch = models.CharField("支行", max_length=32)
    create_time = models.DateTimeField('注册时间',auto_now_add=True)


    def __str__(self):
        return "%s(%s)"%(self.bankcard,self.branch)

    class Meta:
        verbose_name = '我的银行'
        verbose_name_plural = '我的银行'

#代理提现表
class WithdrawRecord(models.Model):
    bankid = models.ForeignKey(AgentBank,verbose_name="银行",null=True,blank=True)
    truename = models.CharField("真名", max_length=32)
    phone = models.CharField("手机号", max_length=32, null=True)
    agentid = models.ForeignKey(AgentInfo,verbose_name="代理ID",blank=True)
    account = models.CharField("代理帐号", max_length=32)
    bank = models.CharField("银行", max_length=32)
    bankcard = models.CharField("卡号", max_length=32)
    applymoney=models.IntegerField("申请金额",default=0)
    create_time = models.DateTimeField('申请时间',auto_now_add=True)
    status = models.IntegerField("状态",default=0)#1已发，0未,-1退回
    send_time = models.DateTimeField('发送时间',null=True,default=None, blank=True)


    def __str__(self):
        return self.bankcard

    class Meta:
        verbose_name = '提现记录'
        verbose_name_plural = '提现记录'

#玩家表
class UserInfo(models.Model):
    uid = models.CharField("玩家ID", max_length=32,unique=True)
    nickname = models.CharField("玩家名称", max_length=32,blank=True,unique=True)
    password = models.CharField("玩家密码", max_length=32,default='')
    pf = models.CharField("平台", max_length=32)
    head_img = models.CharField("头像", max_length=300)
    GENDER_CHOICES = (
         ('m', u'男'),
         ('f', u'女'),
    )
    gender = models.CharField("性别", max_length=32,choices=GENDER_CHOICES,default='m')
    phone = models.CharField("手机号", max_length=32,null=True,blank=True)
    agentid=models.ForeignKey(AgentInfo,verbose_name='所属代理', null=True,default=None,blank=True)
    create_time = models.DateTimeField('注册时间',auto_now_add=True)
    create_ip=models.IPAddressField("注册IP",null=True)
    login_time = models.DateTimeField('登陆时间',null=True)
    login_ip=models.IPAddressField("登陆IP",null=True)
    gamepoint=models.IntegerField("金币",default=0)
    status = models.IntegerField("状态",default=1)#1正常，0拉黑
    unionid=models.CharField("UnionID", max_length=32)
    appid=models.CharField("平台", max_length=32)
    realname=models.CharField("真名", max_length=18,default='')
    IDcard=models.CharField("身份证", max_length=18,default='')
    #完整头像
    def _get_full_img(self):
        return format_html('<img src="{}" style="width:180px;height:100px;" />'.format(self.head_img))
        "Returns the person's full name."
        #return u'%s %s' % (self.first_name, self.last_name)
    full_img = property(_get_full_img,doc='头像')


    def __str__(self):
        return self.nickname

    class Meta:
        verbose_name = '玩家列表'
        verbose_name_plural = '玩家信息'

#玩家额度变动表
class UserConsumeRecord(models.Model):
    uid = models.ForeignKey(UserInfo, verbose_name='玩家')
    gameid = models.IntegerField("游戏",default=0)
    consumepoint = models.FloatField("消费",default=0)
    lastpoint = models.FloatField("剩余",default=0)
    create_time = models.DateTimeField('时间',auto_now_add=True)
    TYPE_CHOICES = (
         (1, u'开房间'),
         (2, u'道具使用'),
        (11, u'微信充值'),
         (12, u'支付宝充值'),
         (21, u'分享赠送'),
         (98,u'管理员扣除'),
        (99, u'管理员充值'),
        (100, u'其它'),
    )
    typeid = models.IntegerField("类型",choices=TYPE_CHOICES,default=100)
    remark=models.CharField("备注", max_length=32)
    requestkey=models.CharField("请求密钥", max_length=40,blank=True)
    isread = models.IntegerField("可读", default=0)

    def __str__(self):
        return str(self.uid_id)

    class Meta:
        verbose_name = '玩家钻石明细'
        verbose_name_plural = '玩家钻石明细'

#玩家拓展表
class UserExpand(models.Model):
    uid = models.ForeignKey(UserInfo, verbose_name='玩家')
    game = models.ForeignKey(GameInfo, verbose_name='游戏')
    typeid = models.IntegerField("类型",default=0)#0为总局数，其它为游戏需要的
    amount = models.IntegerField("数量",default=1)

    def __str__(self):
        return str(self.uid_id)

    class Meta:
        verbose_name = '玩家拓展表'
        verbose_name_plural = '玩家拓展表'

#banner表
class BannerInfo(models.Model):
    name = models.CharField("名称", max_length=32)
    img = models.ImageField("图片", upload_to=settings.UPLOAD_ROOT+"/banner", max_length=200, blank=True)
    app = models.ForeignKey(PlatformInfo,verbose_name="平台")
    url = models.CharField("链接", max_length=100)

    def __str__(self):#关联时显示的信息
        return self.name

    class Meta:
        verbose_name = 'Banner管理'
        verbose_name_plural = 'Banner列表'

#游戏服务器表
class ServerInfo(models.Model):
    game = models.ForeignKey(GameInfo,verbose_name="游戏")
    ip = models.CharField("地址", max_length=32)
    port = models.IntegerField("端口")
    create_time = models.DateTimeField("创建时间",auto_now_add=True)
    STATUS_CHOICES = (
         (0, u'关闭'),
        (1, u'开放'),
    )
    status = models.IntegerField("状态",default=0,choices=STATUS_CHOICES)

    def __str__(self):
        return self.ip

    class Meta:
        verbose_name = '游戏服务器信息'
        verbose_name_plural = '游戏服务器信息列表'

#开桌统计表,按日汇总
class TableReport(models.Model):
    gameid = models.IntegerField('游戏ID',default=0,db_index=True)
    ucount = models.IntegerField('玩家数',default=0)
    tcount = models.IntegerField("桌数", default=0)
    tdate = models.DateField("日期",db_index=True,)

    def __str__(self):#关联时显示的信息
        return str(self.gameid)

    class Meta:
        verbose_name = '开桌统计'
        verbose_name_plural = '开桌统计'

# 游戏数据桌面日志表
class TableInfo(models.Model):
    master_fee = models.IntegerField('庄家费用', default=0)
    table_fee = models.IntegerField('桌面费用', default=0)
    profit_fee = models.IntegerField('收益费用', default=0)
    issue = models.IntegerField('期号', default=0)
    table_id = models.IntegerField('桌号ID', default=0)
    create_time = models.DateTimeField('创建时间', auto_now_add=True)

    def __str__(self):
        return str(self.issue)

    class Meta:
        verbose_name = '桌面游戏数据日志表'
        verbose_name_plural = '桌面游戏数据日志表'

# #开桌表
# class TableInfo(models.Model):
#     gameid = models.ForeignKey(GameInfo,verbose_name="游戏ID")
#     uid = models.ForeignKey(UserInfo,verbose_name="玩家ID")
#     roomid = models.IntegerField("房间号", default=0,db_index=True)
#     time = models.IntegerField("时长", default=0)
#     point = models.IntegerField("扣点", default=0)
#     RULE_CHOICES = (
#          (1, u'么半三 30底300封顶'),
#         (4, u'么半4 40底400封顶'),
#     )
#     playtype = models.IntegerField("规则", default=0,choices=RULE_CHOICES)
#     status = models.IntegerField("状态", default=0)#0预扣，1已作实，-1撤销
#     isbanker = models.IntegerField("房主", default=0)
#     create_time = models.DateTimeField('生成时间',auto_now_add=True)
#     game_time= models.DateTimeField('游戏时间',null=True,blank=True)
#     TYPE_CHOICES = (
#          (0, u'WAIT_FOR_GAMEOPEN'),
#          (1, u'DISSOLVE_PLAYTIME_EXPIRED'),
#         (2, u'DISSOLVE_BY_PLAYERS'),
#         (3, u'DISSOLVE_OPENGAME_TIMEOUT'),
#         (4, u'PLAYING_GAME'),
#         (5, u'WAIT_NEXT_ROUND'),
#         (6, u'DISSOLVE_BY_ESCAPE'),
#     )
#     game_status=models.IntegerField("游戏状态", default=0,choices=TYPE_CHOICES)#0预扣，1已作实，-1撤销
#     round=models.IntegerField("局数", default=0)
#     recordid=models.CharField("记录ID", max_length=40)
#     server=models.ForeignKey(ServerInfo,verbose_name="服务器",null=True,blank=True)
#     playnum=models.IntegerField("房间人数", default=0)
#     openparam=models.TextField('配置',max_length=200,default='')
#     agentid=models.ForeignKey(AgentInfo,verbose_name="代理",null=True,blank=True)
#     create_type=models.IntegerField("开房模式", default=0)
#
#     def __str__(self):#关联时显示的信息
#         return str(self.roomid)
#
#     class Meta:
#         verbose_name = '开桌日志'
#         verbose_name_plural = '开桌日志'

#房间预扣表
class WithholdInfo(models.Model):
    tableid = models.ForeignKey(TableInfo,verbose_name="房间ID")
    uid = models.ForeignKey(UserInfo,verbose_name="玩家ID")
    status = models.IntegerField("状态", default=0)
    create_time = models.DateTimeField('生成时间',auto_now_add=True)
    isread = models.IntegerField("可读", default=0)

    def __str__(self):#关联时显示的信息
        return str(self.uid_id)

    class Meta:
        verbose_name = '预扣记录'
        verbose_name_plural = '预扣记录'

#游戏记录表
class GameRecord(models.Model):
    gameid = models.ForeignKey(GameInfo,verbose_name="游戏ID",db_index=True)
    recordid= models.CharField("局编号", max_length=40,db_index=True)
    uid = models.ForeignKey(UserInfo,verbose_name="玩家ID",db_index=True)
    nickname = models.CharField("呢称", max_length=32)
    roomid = models.IntegerField("房间号", default=0,db_index=True)
    roundid = models.IntegerField("局号", default=0)
    score = models.IntegerField("分数", default=0)
    create_time = models.DateTimeField('生成时间',auto_now_add=True)
    start_time = models.DateTimeField('游戏时间')

    def __str__(self):#关联时显示的信息
        return str(self.uid_id)

    class Meta:
        verbose_name = '游戏记录'
        verbose_name_plural = '游戏记录'

#玩家充值记录
class UserRecharge(models.Model):
    #operid = models.ForeignKey(AgentInfo,verbose_name="操作者",null=True,blank=True,default=None)
    operid = models.CharField("操作者", max_length=32)
    #uid = models.IntegerField("玩家ID", max_length=32)
    uid = models.ForeignKey(UserInfo,verbose_name="玩家ID")
    classid= models.CharField("级别", max_length=32)
    nickname = models.CharField("呢称", max_length=32)
    amount = models.IntegerField("数量", default=0)
    lastpoint=models.IntegerField("当前点数", default=0)
    create_time = models.DateTimeField('生成时间',auto_now_add=True)
    amount = models.IntegerField("数量", default=0)
    money = models.FloatField("金额", default=0)
    PAY_CHOICES = (
         (0, u'微信'),
        (1, u'支付宝'),
    )
    paytype= models.IntegerField("付款方式", default=0,choices=PAY_CHOICES)
    orderid = models.CharField("订单", max_length=36,blank=True)
    out_orderid = models.CharField("订单ID", max_length=36,blank=True)
    gamedata = models.TextField("游戏请求", max_length=300,blank=True)
    appid=models.CharField("来源", max_length=32)#2017.8.5哪个平台来的
    is_sync= models.IntegerField("同步", default=0)

    def __str__(self):#关联时显示的信息
        return self.nickname

    class Meta:
        verbose_name = '玩家充值记录'
        verbose_name_plural = '玩家充值记录'

#代理充值记录
class AgentRecharge(models.Model):
    operid = models.ForeignKey(AgentInfo,verbose_name="操作者",null=True,blank=True,default=None)
    agentid = models.IntegerField("代理ID")
    username = models.CharField("名称", max_length=32)
    money = models.IntegerField("金币", default=0)
    amount = models.IntegerField("数量", default=0)
    lastpoint=models.IntegerField("当前点数", default=0)
    create_time = models.DateTimeField('生成时间',auto_now_add=True)

    def __str__(self):#关联时显示的信息
        return self.username

    class Meta:
        verbose_name = '代理充值记录'
        verbose_name_plural = '代理充值记录'

#代理提成记录
class CommissionReport(models.Model):
    account = models.CharField("帐号", max_length=32,default='')#系统为空，其它为代理
    classid = models.CharField("级别", max_length=32,default='')
    money = models.FloatField("金额", default=0)
    commission = models.FloatField("提成", default=0)
    paytype=models.IntegerField("支付类型", default=0)
    pay_date = models.DateField('日期')
    appid = models.CharField("平台", max_length=32,default='')#2017.8.15哪个平台来的

    def __str__(self):#关联时显示的信息
        return self.username

    class Meta:
        verbose_name = '代理提成记录'
        verbose_name_plural = '代理提成记录'

#玩家反馈表
class Feedback(models.Model):
    uid = models.ForeignKey(UserInfo,verbose_name="用户",null=True,blank=True,default=None)
    TYPE_CHOICES = (
         (1, u'意见反馈'),
         (2, u'违法举报'),
        (3, u'游戏建议'),
         (4, u'充值问题'),
        (5, u'扣钻问题'),
         (6, u'掉线问题'),
        (7, u'商务合作'),
    )
    typeid = models.IntegerField("类型", default=0,choices=TYPE_CHOICES)
    gameid = models.ForeignKey(GameInfo,verbose_name="游戏ID")
    username = models.CharField("名称", max_length=32)
    phone = models.CharField("手机", max_length=32)
    problem=models.TextField("问题", max_length=200)
    create_time = models.DateTimeField('反馈时间',auto_now_add=True)
    STATUS_CHOICES = (
         (0, u'未回复'),
         (1, u'已回复'),
    )
    status = models.IntegerField("状态", default=0,choices=STATUS_CHOICES)
    replay = models.TextField("回复", max_length=200)
    operid = models.ForeignKey(User,verbose_name="操作者",null=True,blank=True,default=None)
    oper_time = models.DateTimeField('处理时间',null=True,auto_now=True)

    def __str__(self):#关联时显示的信息
        return self.get_typeid_display()

    class Meta:
        verbose_name = '反馈记录'
        verbose_name_plural = '反馈记录'

#代理局数统计表
class AgentTableReport(models.Model):
    agent = models.ForeignKey(AgentInfo,verbose_name="代理",null=True,blank=True,default=None)
    time_15 = models.IntegerField("15分钟",default=0)
    time_20 = models.IntegerField("20分钟",default=0)
    time_30 = models.IntegerField("30分钟",default=0)
    time_60 = models.IntegerField("60分钟",default=0)
    allmoney = models.FloatField("金额",default=0)
    create_date=models.DateField('日期')
    gameid = models.IntegerField('游戏ID',default=0,db_index=True)

    def __str__(self):
        return str(self.agent_username)

    class Meta:
        verbose_name = '代理局数统计'
        verbose_name_plural = '代理局数统计'

###################其它#####################
#消息中心
class NewsInfo(models.Model):
    title = models.CharField("标题", max_length=32)
    content = models.TextField("内容", max_length=200)
    create_time = models.DateTimeField("创建时间",auto_now_add=True)

    def __str__(self):
        return self.title

    class Meta:
        verbose_name = '消息'
        verbose_name_plural = '消息列表'

#系统配置
class SystemConfig(models.Model):
    typeid = models.CharField("类型", max_length=32)
    content = models.TextField("内容", max_length=200)
    remark = models.CharField("备注", max_length=32)
    create_time = models.DateTimeField("创建时间",auto_now_add=True)

    def __str__(self):
        return self.typeid

    class Meta:
        verbose_name = '系统配置'
        verbose_name_plural = '系统配置'


# Create your models here.
#快乐8表
class LotteryInfo(models.Model):
    id = models.BigIntegerField(primary_key=True,unique=True)
    issue = models.IntegerField("期号",unique=True)
    result = models.CharField("结果", max_length=100)
    extra = models.CharField("飞盘", max_length=60)
    open_time = models.DateTimeField("开盘时间",)
    create_time = models.DateTimeField('抓取时间',auto_now_add=True)

    def __str__(self):
        return str(self.issue)

    class Meta:
        verbose_name = '快8开奖记录'
        verbose_name_plural = '快8开奖记录'


# #玩家注册表
# class UserInfo(models.Model):
#     account = models.CharField('账户',max_length=100,default='')
#     password = models.CharField('密码',max_length=100,default='')
#     register_time = models.DateTimeField('注册时间',auto_now_add=True)
#     head = models.CharField('用户头像', max_length=100)
#     gold = models.IntegerField('用户金币',default=0)
#
#     def __str__(self):
#         return self.account
#
#
#     class Meta:
#         verbose_name = '用户列表'
#         verbose_name_plural = '用户列表'


#在游戏增(减)加玩家游戏金币记录表
class IncrInfo(models.Model):
    lottery_id=models.IntegerField('期号ID')
    #lottery= models.ForeignKey(LotteryInfo,default=0)
    issue = models.IntegerField('期号',default=0)
    table_id = models.IntegerField('桌号ID',default=0)
    user= models.ForeignKey(UserInfo,default=0)
    amount = models.FloatField('金币增减数',default=0)
    changed_gold = models.FloatField('增减后的金币',default=0)
    remark = models.CharField('描述',max_length=100,default='')
    game_type = models.IntegerField('游戏类型',default=0)
    create_time=models.DateTimeField('创建时间',auto_now_add=True)
    def __str__(self):
        return str(self.issue)


    class Meta:
        verbose_name = '游戏玩家金币记录表'
        verbose_name_plural = '游戏玩家金币记录表'


#游戏数据玩家日志表
class UserGamelog(models.Model):
    user = models.ForeignKey(UserInfo,default=0)
    issue = models.IntegerField('期号',default=0)
    table_id = models.IntegerField('桌号ID',default=0)
    is_master = models.IntegerField('是否坐庄',default=0)
    gain_goldpoint = models.IntegerField('输赢金币数',default=0)
    bet_places = models.CharField('下注期号的数字',max_length=600,default='')
    create_time = models.DateTimeField('创建时间',auto_now_add=True)


    def __str__(self):
        return str(self.issue)


    class Meta:
        verbose_name = '玩家游戏数据日志表'
        verbose_name_plural = '玩家游戏数据日志表'





#充值订单数据表
class PayInfo(models.Model):
    order_id = models.CharField('order_id',max_length=100,default='')
    user = models.ForeignKey(UserInfo,default=0)
    goldpoint = models.IntegerField('充值金币数',default=0)
    pay_time = models.DateTimeField('充值时间',auto_now_add=True)

    def __str__(self):
        return self.order_id

    class Meta:
        verbose_name = '充值订单数据表'
        verbose_name_plural = '充值订单数据表'




#代理提成统计表
#按天每代理次统计一条
class Agent_Profit(models.Model):
    agentid=models.ForeignKey(AgentInfo,verbose_name='代理ID')
    account =models.CharField('账号',max_length=100,default='',blank=True)
    profit =models.IntegerField('提成',default=0)
    date=models.DateField('日期',auto_now_add=True)

    def __str__(self):
        return str(self.agentid)

    class Meta:
        verbose_name = '代理提成统计表'
        verbose_name_plural = '代理提成统计表'



#代理提成记录表
class Detaile_Profit(models.Model):
    uid =models.ForeignKey(UserInfo,verbose_name='玩家ID')
    account =models.CharField('账号',max_length=100,default='',blank=True)
    agent_account=models.CharField('代理账号',max_length=100,default='',blank=True)
    agent_profit=models.IntegerField('代理提成',default=0)
    issue =models.IntegerField('期号',default=0)
    create_time=models.DateTimeField('创建时间',auto_now_add=True)

    def __str__(self):
        return self.account

    class Meta:
        verbose_name = '代理提成明细'
        verbose_name_plural = '代理提成明细'


#管理员，代理充值、回收、扣除提成记录
class Oper_Record(models.Model):
    account=models.CharField('账号',max_length=200,default='')
    ACCOUNT_TYPE=(
        (1,u'会员'),
        (2,u'代理')
    )
    account_type=models.IntegerField('账号类型',default=1,choices=ACCOUNT_TYPE)
    OPER_TYPE=(
        (1,u'充值'),
        (2,u'回收'),
        (3,u'扣除提成'),
        (4,u'管理员扣除')
    )
    oper_type=models.IntegerField('操作类型',default=0,choices=OPER_TYPE)
    number=models.IntegerField('操作额度',default=0)
    opers=models.CharField('操作者',max_length=100,default='')
    create_time=models.DateTimeField('生成时间',auto_now_add=True)

    def __str__(self):
        return self.account

    class Meta:
        verbose_name = '额度操作记录'
        verbose_name_plural = '额度操作记录'


#支付二维码管理
class Pay_Image(models.Model):
    PAY_WAY=(
        (1,u'微信'),
        (2,u'支付宝')
    )
    pay_way=models.IntegerField('支付方式',choices=PAY_WAY,default=0)
    pay_image=models.ImageField('二维码',default='',upload_to='websys/static')
    remark=models.CharField('备注',default='',max_length=60)
    create_time=models.DateTimeField('时间',auto_now_add=True)

    def __str__(self):
        return str(self.pay_way)

    class Meta:
        verbose_name = '二维码管理'
        verbose_name_plural = '二维码管理'